{%- assign description = content | strip_html | split: " " | join: " " | escape | truncate: 150 -%}
{%- assign version = "1.1.7" -%}
{%- assign addons = "github, i18n, plugins, analytics" | split: ", " -%}

{%- assign schema_date = page.date | default: site.time | date_to_xmlschema -%}
{%- assign schema_modi = site.time | date_to_xmlschema -%}
{%- assign schema_surl = page.url | absolute_url | xml_escape -%}

{% comment %} scss {% endcomment %}
{%- capture site_scss -%}
    @import "jekyll-rtd-theme.scss";
    {% if site.fluid %}@import "fluid.scss";{% endif %}
    {% include assets/custom.scss %} {{ site.scss }}
{%- endcapture -%}

{% comment %} cdn {% endcomment %}
{%- if site.debug -%}
    {%- assign cdn = site.baseurl -%}
{%- else -%}
    {%- assign cdn = "https://cdn.jsdelivr.net/gh/rundocs/jekyll-rtd-theme@" | append: version -%}
{%- endif -%}

{% comment %} github-metadata {% endcomment %}
{%- if site.github_metadata != false -%}
    {%- assign author = site.author | default: site.github.owner_name -%}
    {%- assign branch = site.github.source.branch -%}
    {%- assign commit = site.github.build_revision | slice: 0, 7 -%}
    {%- assign repository_url = site.github.repository_url -%}
    {%- assign issues_url = site.github.issues_url -%}
    {%- assign zip_url = site.github.zip_url -%}
{%- else -%}
    {%- assign author = site.author -%}
    {%- assign branch = "" -%}
    {%- assign commit = "" -%}
    {%- assign repository_url = "" -%}
    {%- assign issues_url = "" -%}
    {%- assign zip_url = "" -%}
    {%- assign addons = "i18n, plugins, analytics" | split: ", " -%}
{%- endif -%}

{%- include reset/site_pages.liquid %}
{%- include reset/i18n.liquid -%}

{% comment %} title {% endcomment %}
{%- case page.url -%}
    {%- when "/" -%}
        {%- assign title = site.title | append: " · " | append: site.description -%}
    {%- when "/search.html" -%}
        {%- assign title = __search   | append: " · " | append: site.title -%}
    {%- when "/404.html" -%}
        {%- assign title = __404      | append: " · " | append: site.title -%}
    {%- else -%}
        {%- assign title = page.title | default: page.url | append: " · " | append: site.title -%}
{%- endcase -%}

{% comment %} content {% endcomment %}
{%- assign content = content
    | replace: '’', "'"
    | replace: '<pre class="highlight"><code>', '<pre class="notranslate">'
    | replace: '<pre><code class="', '<pre class="notranslate '
    | replace: "</code></pre>", "</pre>"
    | replace: '<code class="language-plaintext highlighter-rouge">', '<code class="literal">'
    | replace: "<dl>", '<dl class="definition">'
    | replace: "<table>", '<div class="wy-table-responsive"><table class="docutils">'
    | replace: "</table>", '</table></div>' -%}

{% comment %} prev and next {% endcomment %}
{%- assign workdir_files = site_files | where_exp: "item", "item.dir == page.dir" -%}

{%- assign _index = 0 -%}
{%- for item in workdir_files %}
    {%- if item.url == page.url %}
        {%- assign _index = forloop.index -%}
    {%- endif %}
{%- endfor -%}

{%- for item in workdir_files -%}
    {%- assign _index_prev = _index | minus: 1 -%}
    {%- assign _index_next = _index | plus: 1 -%}
    {%- if forloop.index == _index_prev -%}
        {%- assign prev = item -%}
    {%- endif %}
    {%- if forloop.index == _index_next and page.url != page.dir -%}
        {%- assign next = item -%}
    {%- endif %}
{%- endfor -%}
